// packageInsurance/pages/bullet-admin-detail/bullet-admin-detail.js
import dayjs from 'dayjs'
import user from '../../../utils/user'
import {
    getcompanyseatinfoapi
} from '../../api/seat'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        avatar: user.avatarUrl,
        companyname: user.companyName,
        accountExpireTime: '',
        hasseat: 0,
        usedseat: 0,
        OtherBuySeatCnt: 0,
        list: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {
        user.waitLogin().then(() => {
            this.setData({
                companyname: user.companyName,
                avatar: user.avatarUrl,
            })
        })
        this.getcompanyseatinfo()
    },
    async getcompanyseatinfo() {
        let res = await getcompanyseatinfoapi()
        console.log(res.seatList.list, 'fuiyehg');
        if (res.seatList) {
            res.seatList.list.forEach((ele, index) => {
                ele.seatExpireTime = dayjs(ele.seatExpirationTime).format("YYYY-MM-DD")
                if (ele.updateTime) {
                    ele.updateTime = ele.updateTime.slice(0, 11)
                } else {
                    ele.updateTime = '--'
                }
                if (ele.dueDate) {
                    ele.dueDate = ele.dueDate.slice(0, 11)
                } else {
                    ele.dueDate = '--'
                }
            })
        }
        this.setData({
            hasseat: res.hasSeat,
            usedseat: res.useSeat,
            accountExpireTime: res.accountExpireTime,
            OtherBuySeatCnt: res.OtherBuySeatCnt,
            list: res.seatList.list
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})